package com.yeung.alo;

import java.util.Scanner;

/**
 * 输入一串数, 按照一定规律进行正负变换
 * 然后计算其加和
 */
public class 翻转数列 {
    public static void main(String[] args) {
        int n, m = 0;
        String str = new Scanner(System.in).nextLine();
        if (str.equals(" ")) return;
        String[] split = str.split(" ");
        if (split.length < 2) return;
        n = Integer.valueOf(split[0]);
        m = Integer.valueOf(split[1]);
        int temp = m;
        int seq[] = new int[n];
        //装载序列
        for (int i = 0; i < n; i++) {
            if (temp > 0) {
                seq[i] = -(i + 1);
                --temp;
                if (temp == 0) temp = -m;
            } else {
                seq[i] = i + 1;
                ++temp;
                if (temp == 0) temp = m;
            }

        }
        //计算前n项和
        int sum = 0;
        for (int s : seq)
            sum += s;

        System.out.println(sum);
    }
}
